function ajax(url){
    return new Promise((resolve, reject)=>{
        const xhr = new XMLHttpRequest();
        xhr.open('GET',url)
        xhr.onreadystatechange = () =>{
            if(xhr.readyState===4){
                if(xhr.status>=200 && xhr.status<=299){
                    resolve(JSON.parse(xhr.responseText))
                }else{
                    reject(new Error(`请求失败 status=${xhr.status}`))
                }
            }
        }
        xhr.send();
    })
}